package com.demo.juc.future.completableFuture;

import java.util.concurrent.CompletableFuture;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023/5/24 16:55
 * @Version: 1.0
 */
public class Demo4 {

    public static void main(String[] args) {
        CompletableFuture<Integer> future1
                = CompletableFuture.supplyAsync(()->{
            System.out.println("compute 1");
            return 1;
        });
        CompletableFuture<Integer> future2
                = CompletableFuture.supplyAsync(()->{
            System.out.println("compute 2");
            return 10;
        });
        CompletableFuture<Integer> future3
                = future1.thenCombine(future2, (r1, r2)->r1 + r2);
        System.out.println("result: " + future3.join());

    }
}
